package cn.yh.springbootjwt.service.impl;

import cn.yh.springbootjwt.domain.entity.CollectDo;
import cn.yh.springbootjwt.domain.vo.CollectListVo;
import cn.yh.springbootjwt.mapper.CollectMapper;
import cn.yh.springbootjwt.service.ICollectService;
import cn.yh.springbootjwt.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service


public class CollectServiceImpl implements ICollectService {
    @Autowired
    private CollectMapper collectMapper;


    @Override
    public int isCollect(Long productId){
        Long userId = JWTUtils.getUserIdByClaim();
        CollectDo collectDo = collectMapper.isCollect(productId, userId);

        if (collectDo != null){
            return collectMapper.deleteCollect(productId, userId);
        }
        return collectMapper.insertCollect(productId, userId);
    }

    @Override
    public List<CollectListVo> getCollectList() {
        System.out.println("UID:"+JWTUtils.getUserIdByClaim());
        return collectMapper.getCollectList(JWTUtils.getUserIdByClaim());
    }
}
